package com.hx.collection.shardingmap;

import java.util.LinkedHashMap;
import java.util.Map;

public class LinkedHashMapDemo {
    public static void main(String[] args) {
        LRUCache<String, String> cache = new LRUCache<>(3);
        cache.put("a", "hhh");
        cache.put("b", "hhh");
        cache.put("c", "hhh");
        String c = cache.get("c");
        cache.put("d", "hhh");
        System.out.println(cache
        );

    }

    static class LRUCache<K, V> extends LinkedHashMap<K, V> {
        private final int max_size;

        public LRUCache(int max_size) {
            super(max_size);
            this.max_size = max_size;
        }

        @Override
        protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
            return size() > max_size;
        }
    }

}
